package com.jiangjiang.eshop.promotion.biz;

import com.jiangjiang.eshop.order.dto.CouponDTO;
import com.jiangjiang.eshop.promotion.convert.CouponConvert;
import com.jiangjiang.eshop.promotion.domain.CouponAchieveEntity;
import com.jiangjiang.eshop.promotion.service.CouponAchieveService;
import com.jiangjiang.eshop.promotion.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @ClassName PromotionBize
 * @Description TODO
 * @Author jhw
 * @Date 2021/7/22 10:36
 * @Version 1.0
 **/
@Component
public class PromotionBiz {

    @Autowired
    private CouponAchieveService couponAchieveService;

    @Autowired
    private CouponBiz couponBiz;


    /**
     * 查询用户当前可以使用的有效优惠券
     *
     * @param userAccountId 用户账号id
     * @return 有效优惠券
     */
    public List<CouponDTO> listUnusedByUserAccountId(Long userAccountId) {

        Set<Long> couponIdSet = couponAchieveService.listUnusedByUserAccountId(userAccountId)
                .stream()
                .map(CouponAchieveEntity::getCouponId)
                .collect(Collectors.toSet());

        return couponBiz.queryByIds(couponIdSet);

    }
}
